File System Interface
[!abstract]+ File System Interface
- File Concept
- Access Methods
- Disk and Directory Structure
- File System Mounting
- File Sharing
- Protection
File
[!question]+ What is File?
- A named collection of related information that is recorded on secondary storage.
- (e.g. Disk, SSD, Flash, etc.)
- A sequence of bits, bytes, lines, or records
- the meaning of which is defined by the file’s creator
- Smallest logical storage unit for user view
+ File Property
- Contiguous logical address space
- Represents programs or data
[!success]+ File system resides on secondary storage (disks)
- Provides user interface to storage, mapping logical to physical.
- Provides efficient and convenient access to disk by allowing data to be stored, located, retrieved easily.
File Attributes
[!abstract]+ File attributes
- Name – only information kept in human-readable form
- Identifier – unique tag (number) identifies file within file system
- Type – needed for systems that support different types
- Location – pointer to file location on device
- Size – current file size
- Protection – controls who can do reading, writing, executing
- Time, date, and user identification – data for protection, security, and usage monitoring
- Information about files metadata are kept in the directory structure, which is maintained on the disk
File Operation
[!abstract]+ Basic File Operations
- Create a file
- Write a file
- Read a file
- Reposition within a file
- Truncate a file^[截断文件的操作通常用于快速清空文件内容而不删除文件本身,这在需要保留文件但不需要其内容的场景中非常有用。例如,日志文件管理中,当日志文件达到一定大小需要被清空重写时,可以使用截断操作来实现。]
- File is reset to length zero
- 当一个文件被截断时,其内容被清空,文件的长度被重置为零。这意味着文件中原有的所有数据都将被删除。
- File space is released
- 截断文件后释放的空间指的是之前文件内容所占用的存储空间被系统回收。这样可以提高存储效率,为其他文件或数据释放空间。
- File attributes are unchanged
- 尽管文件的内容和大小发生了改变,文件的属性(如修改时间、访问权限等)保持不变。这意味着文件的元数据,除了与文件大小相关的部分,不会因为截断操作而受到影响。
- Delete a file
Except file creation and deletion, all other operations need to open the file first and then close the file after the operation
File Locking
- Lock of file is provided by some operating systems
- Similar to reader writer locks
[!abstract]+ Two Kinds of Lock Shared lock
- Similar to reader lock
- Several processes can acquire concurrently
Exclusive lock
- Similar to writer lock
- Mandatory lock
- Once a process acquires an exclusive lock, the operating system will prevent any other process from accessing the locked file
- Windows
- Advisory lock
- it is up to software developers to ensure that locks are appropriately acquired and released
- Unix/Linux
File Types
The OS uses the extension to indicate the type of the file.
[!example]- Most common types
- .c
- .exe
- .docx
- .jpg
- .png
- .zip
File Access Methods
- Sequential Access
- Direct/Random Access
[!abstract]+ Access Methods
- Sequential Access
- Commands
- read_next
- write_next
- reset (to the beginning)
- Direct/Random Access
- Commands
- read next
- write next
- read n
- write n
- position to n
- rewrite n
n = an index relative to the beginning of the file
- Index and Relative Files
- Keep index in memory for fast determination of location of data to be operated on
- E.g., VMS OS
Directory and Disk Structure
Directory Structure
A directory structure (per file system) is used to organize the files
Both the directory structure and the files reside on disk
Disk Structure
- Drive 驱动器
- Partition 分区
- Volume 卷
Drive
- A drive is a physical block disk.
- A drive can be subdivided into several logic block disks (partitions)
Partition
- Disk or partition can be used raw
- i.e., without a file system
- Partition can be formatted with a file system (cooked)
- Root partition contains the OS kernel, and other system files
- Other partitions can hold other
OSes
, other file systems, or be raw.
Volume
- A volume is a single accessible storage area with a single file system, a volume can contain multiple partitions
File system types
- General-purpose file systems
- Mostly used, like Windows
- Special-purpose file systems
- Solaris’s contract file system
+ Basic operations
- Search for a file
- Create a file
- Delete a file
- List a directory
- Rename a file
- Traverse the file system
The directory is organized logically to obtain
- Efficient location of a files
- Naming convenient to users
- Two files in different directories can have the same name
- The same file can have several different names
- Grouping of files with similar properties
- put photos in a directory
Directory organization
- Single level directory
- Two-level directory
- Tree-structured directories
- Acyclic graph directories
Tree Structured directories
Tree structures is a tree of arbitrary height, mostly common directory structure
- It allows users to create their own subdirectories and to organize their files accordingly.
- Advantages
- Efficient searching
- Grouping capability
Acyclic-Graph Directories
- A tree structure prohibits the sharing of files or directories.
- An acyclic graph (a graph with no cycles) allows directories to share subdirectories and files
- A file may have multiple different path names
- Some
OSes
simply do not allow shared directories or links
[!question]+ How do we guarantee no cycles?
Allow only links to file not subdirectories
Every time a new link is added, use a cycle detection algorithm to determine whether it is OK. Very expensive.
File System Mounting
- A file system must be mounted before it can be accessed
- An unmounted file system can be mounted at a mount point
- The amount point must be an empty directory
- i.e., original file system at the mount point must be removed if exists
File Sharing
- A file can be shared by multiple users
- Access might be protected
- The owner of a file is the user who can change attributes and grant access and who has the most control over the file.
- The group attribute defines a subset of users who can share access to the file § The owner and group IDs of a given file (or directory) are stored as part of file attributes
- User IDs identify users, allowing permissions and protections for a user
- Group IDs allow users to be in groups, permitting group access rights
File Protection
When information is stored in a computer system, we want to keep it safe from physical damage (the issue of reliability) and improper access (the issue of protection)
File owner/creator should be able to control:
- what can be done
- by whom
Types of access
- Read: Read from the file.
- Write: Write or rewrite the file.
- Execute: Load the file into memory and execute it.
- Append: Write new information at the end of the file.
- Delete: Delete the file and free its space for possible reuse.
- List: List the name and attributes of the file
Other operations, such as renaming, copying, and editing the file, are high levels, done through read, write access.
Access Lists and Groups
- Each file and directory has an access-control list (ACL)
- lists user names and the types of access allowed for each user.
- Three modes of access
- Read (R),
- Write (W)
- Execute (X)
- The UNIX system defines three fields (owner, group, public) of three bits (RWX)
- Three classes of users on Unix / Linux
Three classes of users on Unix / Linux RWX creator
- Owner access 7 111
- Group access 6 110
- Public access 1 001
Remote File Sharing
+ Four implementation methods for remote file sharing
- Manually transferring files between machines via programs like ftp (file transfer protocol) 4 both anonymous and authenticated access
- Use a distributed fil system (DFS), in which remote directories are visible from a local machine 4 tighter integration between the machine
- The World Wide Web, is a reversion to the first. Use a browser to gain access to the remote files, and separate operations (essentially a wrapper for ftp) 4 anonymous access
- Cloud computing 4 delivers computing, storage, and even applications as a service across a network.